<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="com.webapp.model.Comment, com.webapp.model.CommentModel, java.util.List, com.webapp.model.CircleModel, com.webapp.model.Circle" %>
<% 
	List comments =  (List)session.getAttribute("Comments");
	int postid = Integer.parseInt((String)session.getAttribute("Post"));
%>
<!-- include moo talk header file -->
<%@ include file="MooTalkHeader.jsp" %>
<style>
	#holderP { overflow:auto; width: 500px; margin: 0px auto 0px auto;}
	#content { width: 200px; float: left; padding: 10px; }
	#count { width: 200px; padding:10px; float:right;}
</style>
		<div id="site_content_text">
		<% 
				String x = request.getParameter("comment"); 
				if(x != null) {
					
					if(x.equals("added")) {
						%>
							<p style="color:red;">
								Comment Added!
							</p>
						<%
					}
					
					if(x.equals("added")) {
						%>
							<p style="color:red;">
								Your fence was built! Please have a great day!
							</p>
						<%
					}
					
					if(x.equals("deleted")) {
						%>
							<p style="color:red;">
								Your fence was removed!
							</p>
						<%
					}
				}
			%>
			<h2>Barnyard</h2>
			
			<% if (comments != null) { %>
				<% for ( int i = 0; i < comments.size(); i++) { %>
				<% Comment comment = (Comment)comments.get(i);%>
				<!--  grid type layout -->
				<% if ( i % 2 == 0) { %>
				<div class="even">
				<% } else if( i%2 == 1) { %>
				<div class="odd">
				<% } %>
					<div id="postOrComment">
		
						<div id="holderP">
							<div id="content">
								<p><%=comment.getContent()%></p>
							</div>
			
							<div id="count">
								<% CommentModel cm = new CommentModel(); %>
								+<%=cm.numberOfLikes(comment.getCommentId())%>
								<strong>Date:</strong><br/><%=comment.getDate()%><br/>
								<strong>Author:</strong><br/> <%=comment.getAuthor()%><br/>
							</div>
						</div>
						
						<div id="navigation">
								<% 
								User theUser = (User) user;
								if ( theUser.getUserId() == comment.getAuthor()) { %>
									<form action="EditComment.do" method="post">
										<input type="hidden" name="COMMENTID" value="<%=comment.getCommentId()%>" />
										<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
										<input type="hidden" name="POSTID" value="<%=postid%>" />
										<textarea rows="4" cols="20 " name="COMMENTTXT"><%=comment.getContent()%></textarea><br/>
										<input type="hidden" value="<%=comment.getAuthor()%>" />
										<input class="btn" type="submit" value="Edit Comment!"/>
									</form>
							<% } %>
							
							<form action="Like.do" method="post">
								<input type="hidden" name="COMMENTID"value="<%=comment.getCommentId()%>" />
								<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
								<input class="btn" type="submit" value="Like Comment!"/>
							</form>
							
							<form action="Dislike.do" method="post">
								<input type="hidden" name="COMMENTID" value="<%=comment.getCommentId()%>" />
								<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
								<input class="btn" type="submit" value="Dislike!"/>
							</form>
							
							<% 
								if ( theUser.getUserId() == comment.getAuthor()) { %>
									<form action="RemoveComment.do" method="post">
										<input type="hidden"  name="COMMENTID" value="<%=comment.getCommentId()%>" />
										<input type="hidden" name="POSTID" value="<%=postid%>" />
										<input class="btn" type="submit" value="Remove Comment!"/>
									</form>
							<% } %>
							
						</div>
					</div>	
				</div>
				<% } %>
			<% } else { %>
			<p>No Comments!</p>
			<% } %>
		</div>
		
<!--  include moo talk footer file -->
<%@ include file="MooTalkFooter.jsp" %>
